<?php
	include('include/header.php');
?>

<div class="body">
	<form id="executeQuery" action="include/controller.php" method="POST">
	</br>
		<input type="hidden" name="command" value="executeQuery"/>
		<input type="text" name="query" size="180" />
		<input type="submit" value="Execute Query"/> </br>
		<p> Query Type: </p>
		<input type="radio" name="type" value="select" checked> Select</br>
		<input type="radio" name="type" value="insert"> Insert</br>
		<input type="radio" name="type" value="drop"> Drop </br>
		<input type="radio" name="type" value="update"> Update </br>
	</form>
</br>

<?php
	function generateTable($data) {

		if(!is_array($data)){
			print($data);
			return;
		}
		
		echo "Query Result:";
		echo "<table>";
		//Print header
		foreach($data[0] as $key =>$value) {
			echo "<th>";
			echo $key;
			echo "</th>";
		}
		//Each tuple
		foreach($data as $rows) {
			echo "<tr>";
				foreach($rows as $column) {
					echo "<td>".$column."</td>";
				}
			echo "</tr>";
		}
		echo "</table>";
	
	}
	if(isset($_SESSION["result"])){
		$result = $_SESSION["result"];
		generateTable($result);
	}
 
	unset($_SESSION["result"]);
?>
</div>
<?php
	include('include/footer.php');
?>